Skip to content

libnative: generic retry() for 64 bit read/write(). #17020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2014

Conversation

nodakai
Copy link
Contributor

@nodakai nodakai commented Sep 5, 2014

The current implementation of retry() cannot handle, say, write() of >2 GB data because it truncates the return value of the closure parameter into c_int which is (almost always) only 32 bit.

This is my first code to use traits... I hope #[inline] works as intended.

I think mkerr_libc() is still causing bugs here and there; I'll fix them later.

fn retry_base <Int: PartialEq + One + Neg<Int>>
(f: || -> Int, eintr: int) -> Int {
let one: Int = one();
let minus_one = one.neg();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just write -one::<Int>() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I spent nearly 30 minutes to find a way to call a trait method without &self...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in this case one is just a standalone function that wraps the trait. The actual trait method would be called like One::one() and that currently doesn't allow for type hints (requires UFCS).

Also, the style is for functions to be called module-qualified, e.g. import use std::num; and call num::one() and num::zero() (although that can actually just be !ret.is_zero()). In this case, you can use the mod sugar for imports, like use std::num::{mod, One, Zero};, which brings those to traits into scope, as well as the module (i.e. the mod is equivalent to use std::num;)

@alexcrichton
Copy link
Member

Thanks for this! Also sorry for my sloppiness in taking too long to make this generic :(

@nodakai
Copy link
Contributor Author

nodakai commented Sep 6, 2014

I cleaned up module imports according to @huonw's suggestion.

#[off-topic] A math-savvy person will find the One trait odd for not inheriting from the Mult trait

@nodakai
Copy link
Contributor Author

nodakai commented Sep 7, 2014

retry() is useless on Windows.

I'm getting to understand that Win32/WinSock2 API never calls WSASetLastError() with WSAEINTR unless a programmer specifically cancels the ongoing blocking call by a deprecated WinSock1 API WSACancelBlockingCall

Windows' equivalent of SIGINT is always handled in a separate thread

@alexcrichton
Copy link
Member

It's ok to make the windows version of retry to just call the closure once.

@nodakai
Copy link
Contributor Author

nodakai commented Sep 7, 2014

It should be OK now, but I have no Windows box at hand...

@alexcrichton
Copy link
Member

Thanks @nodakai! Could you squash these commits down as well?

@nodakai nodakai force-pushed the libnative-c_int branch 2 times, most recently from 680be1a to 3b43506 Compare September 7, 2014 23:57
Win32/WinSock APIs never call WSASetLastError() with WSAEINTR
unless a programmer specifically cancels the ongoing blocking call by
a deprecated WinSock1 API WSACancelBlockingCall().
So the errno check was simply removed and retry() became an id function
on Windows.
Note: Windows' equivalent of SIGINT is always handled in a separate thread:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682541%28v=vs.85%29.aspx
"CTRL+C and CTRL+BREAK Signals"

Also, incidentally rename a type parameter and clean up some module imports.
@nodakai
Copy link
Contributor Author

nodakai commented Sep 8, 2014

@alexcrichton Noted,

pick b8911d7 libnative: generic retry() for 64 bit read/write().
s 1465cd7 libnative/io: clean up some of module imports.
s 680be1a libnative/io: fix a compile error on Windows due to b8911d7
s e8d77a6 libnative/io: fix compile error in 0117be7.

all squashed into 52e99cb

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 9, 2014
@bors bors merged commit 52e99cb into rust-lang:master Sep 9, 2014
@nodakai nodakai deleted the libnative-c_int branch September 10, 2014 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants